
(function(){
	var api = 'http://h6.duchengjiu.top/shop/';
	var hotContent = document.getElementById('goods-hot');
	var templateStr = document.getElementById('template').innerHTML;
	var pages=1;
	var pageCount=0;
	function getGoodsHot(pages){
		$.get(api + 'api_goods.php',{'page':pages,'pagesize':9},function(data){
			pageCount=data.page.page_count;
			console.log(pageCount)
			var obj = data.data;
			var str='';
			var compile = _.template(templateStr);
			//console.log(obj);
			for(var i = 0; i < obj.length; i++){
				str += compile(obj[i]);
			}
			hotContent.innerHTML += str;
			$('[lazyloadsrc]').YdxLazyLoad();
			//分页
	$('.page').pagination({
		pageCount : pageCount, //总多少页
		//current : 1, //默认当前第几页
		activeCls : 'pageCls', //当前选中页样式
		prevContent: '上一页',
		nextContent: '下一页',
		mode : 'fixed',
		count: 4,
		coping: true,
		homePage : '首页',
		endPage : '尾页',
		jump : true,
		callback : function(apis){
			var activePage = apis.getCurrent();
			//console.log(activePage);
			//在当下请求数据
			//getGoodsHot(activePage);
			$.get(api + 'api_goods.php', {'page':activePage, 'pagesize':9}, function(data){
					//console.log(data)
					if(data.code == 1){
						hotContent.innerHTML = '客官别急，新品马上上架!';
						return;
					};
					pageCount = data.page.page_count;
					var obj = data.data;
					//console.log(obj);
					//遍历出数据添加到页面
					var str ='';
					var tempile = _.template(templateStr);
					for(var i = 0; i < obj.length; i++){
						str += tempile(obj[i]);
					};
					hotContent.innerHTML = str;
					//懒加载图片调用
					$('[lazyloadsrc]').YdxLazyLoad();
				});	
			},
		});
	});
	};
	
	getGoodsHot(pages);	
})()
